//
//  ShaiorderCell.m
//  danpin
//
//  Created by chuangjia on 28/8/15.
//  Copyright (c) 2015 chuangjia. All rights reserved.
//

#import "ShaiorderCell.h"

#import "ZUIImageView.h"
#import "UIButtonView.h"
#define IMAGEHEIGHT 180
@interface ShaiorderCell()
{
    
}
@property (nonatomic, strong) UIView *bgView;
@property(nonatomic,strong)UIImageView *iconView;
@property(nonatomic,strong)UILabel *userLable;
@property(nonatomic,strong)UILabel *timeLable;


@property (nonatomic, strong) UIScrollView* imgBackView ;
@property (nonatomic, strong) UIImageView *pimageView;
@property(nonatomic,strong)UILabel *skuNameLabel;
@property(nonatomic,strong)UIView *skuNameLine;
@property(nonatomic,strong)RTLabel *skuNameContent;
@property(nonatomic,strong)RTLabel *cateLabel;
@property(nonatomic,strong)RTLabel *brandLabel;
@property (nonatomic, strong) UIButtonView *btnLikeV;
@property (nonatomic, strong) UIButtonView *btnReplyV;
@property (nonatomic, strong) UIView *commentView;
@property(nonatomic,strong)UILabel *priceLabel;
@property(nonatomic,strong)UILabel *photoLabel;
@property(nonatomic,strong)UILabel *levelLabel;
@property(nonatomic,strong)UIButton *followBtn;
@property(nonatomic,strong)UIButton *moreBtn;
@property(nonatomic,strong)UIImageView *shaidanView;
@property(nonatomic,strong)UIImageView *brandView;
@property(nonatomic,strong)UIImageView *lineView;
@end


@implementation ShaiorderCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        _bgView = [[UIView alloc] initWithFrame:CGRectZero];
        _bgView.backgroundColor =[UIColor clearColor];
        [self.contentView addSubview:_bgView];
        //
        UITapGestureRecognizer* singleRecognizer4= [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapFromUser)];
        _iconView =[[UIImageView alloc] initWithFrame:CGRectZero];
        _iconView.layer.cornerRadius=PHOTO_FRAME_WIDTH*1.5;
        _iconView.layer.masksToBounds = YES;
        _iconView.userInteractionEnabled=YES;
        [_iconView addGestureRecognizer:singleRecognizer4];
        [_bgView addSubview:_iconView];
        singleRecognizer4=nil;
        
        UITapGestureRecognizer* singleRecognizer5= [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapFromUser)];
        _userLable =[[UILabel alloc] initWithFrame:CGRectZero];
        _userLable.backgroundColor = [UIColor clearColor];
        _userLable.textColor = [UIColor darkGrayColor];
        _userLable.textAlignment = NSTextAlignmentLeft;
        _userLable.font =FONT(14);
        _userLable.numberOfLines=0;
        _userLable.userInteractionEnabled=YES;
        [_userLable addGestureRecognizer:singleRecognizer5];
        [_bgView addSubview:_userLable];
        singleRecognizer5=nil;
        
        _timeLable =[[UILabel alloc] initWithFrame:CGRectZero];
        _timeLable.backgroundColor = [UIColor clearColor];
        _timeLable.textColor = UIColorFromRGB(0x999999);
        _timeLable.textAlignment = NSTextAlignmentLeft;
        _timeLable.font = FONT(10);
        _timeLable.numberOfLines=0;
        [_bgView addSubview:_timeLable];
        
        _levelLabel =[[UILabel alloc] initWithFrame:CGRectZero];
        _levelLabel.backgroundColor = [UIColor blackColor];
        _levelLabel.textColor = [UIColor whiteColor];
        _levelLabel.textAlignment = NSTextAlignmentCenter;
        _levelLabel.font = FONT(9);
        [_bgView addSubview:_levelLabel];
        //
        _followBtn =[UIButton buttonWithType:UIButtonTypeCustom];
        _followBtn.backgroundColor =[UIColor clearColor];
        _followBtn.layer.borderColor=UIColorFromRGB(0xcccccc).CGColor;
        _followBtn.layer.borderWidth =0.5;
        _followBtn.layer.cornerRadius = 2.5;
        _followBtn.titleLabel.font = FONT(12);
        [_followBtn addTarget:self action:@selector(followAction) forControlEvents:UIControlEventTouchUpInside];
        [_bgView addSubview:_followBtn];
        //
        //
//        _moreBtn =[UIButton buttonWithType:UIButtonTypeCustom];
//        _moreBtn.backgroundColor =[UIColor clearColor];
//        [_moreBtn setImage:[UIImage imageNamed:@"more_icon.png"] forState:UIControlStateNormal];
//        [_moreBtn addTarget:self action:@selector(moreAction) forControlEvents:UIControlEventTouchUpInside];
//        [_bgView addSubview:_moreBtn];
        //
        
        
        _imgBackView = [[UIScrollView alloc]initWithFrame:CGRectZero];
        _imgBackView.scrollEnabled = NO;
        _imgBackView.backgroundColor = [UIColor clearColor];
        [_bgView addSubview:_imgBackView];
        
        UITapGestureRecognizer* singleRecognizer= [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapFrom)];
        _pimageView =[[UIImageView alloc] initWithFrame:CGRectZero];
        _pimageView.backgroundColor =UIColorFromRGB(0xffffff);
        _pimageView.userInteractionEnabled =YES;
        _pimageView.contentMode = UIViewContentModeScaleAspectFit;
        [_pimageView addGestureRecognizer:singleRecognizer];
        [_imgBackView addSubview:_pimageView];
        singleRecognizer=nil;
        
        _brandView=[[UIImageView alloc] initWithFrame:CGRectZero];
        _brandView.image = [UIImage imageNamed:@"jbc_bg.png"];
        _brandView.alpha =0.9;
        [_bgView addSubview:_brandView];
        
     //   imgBackView = nil;
        
        //
        
        UITapGestureRecognizer* singleRecognizer1= [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapFrom)];
        _skuNameLabel =[[UILabel alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH,0, DEVICE_WIDTH-PHOTO_FRAME_WIDTH*2,0)];
        _skuNameLabel.backgroundColor = [UIColor clearColor];
        _skuNameLabel.textColor = [UIColor whiteColor];
        _skuNameLabel.textAlignment = NSTextAlignmentLeft;
        _skuNameLabel.font = FONT(16);
        _skuNameLabel.userInteractionEnabled =YES;
        [_skuNameLabel addGestureRecognizer:singleRecognizer1];
        [_brandView addSubview:_skuNameLabel];
        singleRecognizer1=nil;
        
        _skuNameLine = [[UIView alloc] initWithFrame:CGRectZero];
        _skuNameLine .backgroundColor =[UIColor lightGrayColor];
        [_brandView addSubview:_skuNameLine];
        //
        UITapGestureRecognizer* singleRecognizer3= [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapFrom3)];
        _cateLabel =[[RTLabel alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH,0, DEVICE_WIDTH-PHOTO_FRAME_WIDTH*2,0)];
        _cateLabel.backgroundColor = [UIColor clearColor];
        _cateLabel.textColor = [UIColor whiteColor];
        _cateLabel.textAlignment = NSTextAlignmentLeft;
        _cateLabel.font = FONT(14);
        _cateLabel.lineSpacing =LSpacing;
        _cateLabel.userInteractionEnabled =YES;
        [_cateLabel addGestureRecognizer:singleRecognizer3];
        [_brandView addSubview:_cateLabel];
        singleRecognizer3=nil;
        
        UITapGestureRecognizer* singleRecognizer8= [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapFrom4)];
        _brandLabel =[[RTLabel alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH,0, DEVICE_WIDTH-PHOTO_FRAME_WIDTH*2,0)];
        _brandLabel.backgroundColor = [UIColor clearColor];
        _brandLabel.textColor = [UIColor whiteColor];
        _brandLabel.textAlignment = NSTextAlignmentLeft;
        _brandLabel.font = FONT(14);
        _brandLabel.lineSpacing = 6.0;
        _brandLabel.userInteractionEnabled =YES;
        [_brandLabel addGestureRecognizer:singleRecognizer8];
        [_brandView addSubview:_brandLabel];
        singleRecognizer8=nil;
        
        //
        UITapGestureRecognizer* singleRecognizer2= [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapFrom)];
        _skuNameContent =[[RTLabel alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH,0, DEVICE_WIDTH-PHOTO_FRAME_WIDTH*2,0)];
        _skuNameContent.backgroundColor = [UIColor clearColor];
        _skuNameContent.textColor = [UIColor darkGrayColor];
        _skuNameContent.textAlignment = NSTextAlignmentLeft;
        _skuNameContent.font = FONT(14);
        _skuNameContent.lineSpacing =LSpacing;
        _skuNameContent.userInteractionEnabled =YES;
        [_skuNameContent addGestureRecognizer:singleRecognizer2];
        [_bgView addSubview:_skuNameContent];
        singleRecognizer2=nil;
       
        //
        _commentView = [[UIView alloc] initWithFrame:CGRectZero];
        _commentView.backgroundColor =[UIColor clearColor];
        [_bgView addSubview:_commentView];
        //
        _btnLikeV = [[UIButtonView alloc] initWithFrame:CGRectZero];
        _btnLikeV.backgroundColor =  [UIColor clearColor];
        
        __weak typeof (self) wSelf = self;
        [_btnLikeV setCallBack:^(BEventType t, UIView *v, id data, id key) {
            [wSelf likeAction:nil];
        }];
        [_bgView addSubview:_btnLikeV];
        
        _btnReplyV = [[UIButtonView alloc] initWithFrame:CGRectZero];
        _btnReplyV.backgroundColor =  [UIColor clearColor];
        [_btnReplyV setCallBack:^(BEventType t, UIView *v, id data, id key) {
            [wSelf commentAction:nil];
        }];
        [_bgView addSubview:_btnReplyV];
        
        
        _priceLabel =[[UILabel alloc] initWithFrame:CGRectZero];
        _priceLabel.backgroundColor = [UIColor clearColor];
        _priceLabel.textColor = [UIColor grayColor];
        _priceLabel.textAlignment = NSTextAlignmentLeft;
        _priceLabel.font = FONT(12);
        [_bgView addSubview:_priceLabel];
        
        _photoLabel =[[UILabel alloc] initWithFrame:CGRectZero];
        _photoLabel.backgroundColor = [UIColor grayColor];
        _photoLabel.alpha=0.5;
        _photoLabel.textColor = [UIColor whiteColor];
        _photoLabel.textAlignment = NSTextAlignmentCenter;
        _photoLabel.font = FONT(14);
        _photoLabel.layer.cornerRadius = 3;//(值越大，角就越圆)
        _photoLabel.layer.masksToBounds = YES;
        [_bgView addSubview:_photoLabel];
 
        
        _shaidanView =[[UIImageView alloc] initWithFrame:CGRectZero];
        [self.contentView addSubview:_shaidanView];
        
        
        _lineView =[[UIImageView alloc] initWithFrame:CGRectZero];
        _lineView.backgroundColor=UIColorFromRGB(0xe5e5e5);
        [self.contentView addSubview:_lineView];
    }
    return self;
}
-(void)dealloc
{
    self.actionBlock=nil;
    self.data=nil;
    self.other=nil;
    self.indexPath=nil;
    
    [self.pimageView removeFromSuperview];
    self.pimageView=nil;
    [self.skuNameLabel removeFromSuperview];
    self.skuNameLabel=nil;
    
    [self.skuNameLine removeFromSuperview];
    self.skuNameLine=nil;
    
    [self.skuNameContent removeFromSuperview];
    self.skuNameContent=nil;
    
    [self.cateLabel removeFromSuperview];
    self.cateLabel=nil;
    
    [self.brandLabel removeFromSuperview];
    self.brandLabel=nil;
    
    [self.btnLikeV removeFromSuperview];
    self.btnLikeV=nil;
    
    [self.btnReplyV removeFromSuperview];
    self.btnReplyV=nil;
    
    [self.commentView removeFromSuperview];
    self.commentView=nil;
    [self.priceLabel removeFromSuperview];
    self.priceLabel=nil;
    [self.photoLabel removeFromSuperview];
    self.photoLabel=nil;
    
    [self.userLable removeFromSuperview];
    self.userLable=nil;
    
    [self.timeLable removeFromSuperview];
    self.timeLable=nil;
    
    [self.levelLabel removeFromSuperview];
    self.levelLabel=nil;
    
    [self.brandView removeFromSuperview];
    self.brandView=nil;
    
    [self.shaidanView removeFromSuperview];
    self.shaidanView=nil;
   
    [self.lineView removeFromSuperview];
    self.lineView=nil;
    
    //    DLog(@"%s", __PRETTY_FUNCTION__);
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    _bgView.frame =CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
    
}
- (void)drawRect:(CGRect)rect {
    
    [super drawRect:rect];
    _lineView.frame =CGRectMake(0,self.bounds.size.height-0.5, DEVICE_WIDTH, 0.5);
}
/// 根据数据模型来显示内容
- (void)showInfo:(id)model other:(id)other key:(id)key indexPath:(NSIndexPath *)indexPath
{
    self.other =other;
    self.key =key;
    self.data =model;
    [self showInfo:model indexPath:indexPath];
}
- (void)showInfo:(id)model key:(id)key indexPath:(NSIndexPath *)indexPath
{
    self.key = key;
    self.data =model;
    [self showInfo:model indexPath:indexPath];
}
- (void)showInfo:(id)model indexPath:(NSIndexPath *)indexPath
{
    NSDictionary *dict =(NSDictionary*)model;
    self.data =model;
    self.indexPath=indexPath;
    float fTop = PHOTO_FRAME_WIDTH+PHOTO_TIME_PADDING;
    NSString * iconURL =[[NSString stringWithFormat:@"%@", [[dict objectForKey:@"user"] objectForKey:@"largeFace"]] replaceNullString];
    if (iconURL.length>0) {
        _iconView.frame =CGRectMake(PHOTO_FRAME_WIDTH,fTop, PHOTO_FRAME_WIDTH*3, PHOTO_FRAME_WIDTH*3);
        [_iconView sd_setImageWithURL:[NSURL URLWithString:iconURL] placeholderImage:[UIImage imageNamed:@"user_face.png"]];
        fTop += PHOTO_FRAME_WIDTH*4+PHOTO_TIME_PADDING;
    }
    //
    NSString *nick = [[NSString stringWithFormat:@"%@",[[dict objectForKey:@"user"] objectForKey:@"nick_name"]] replaceNullString];
    if (nick.length>0)
    {
         self.userLable.text =nick;
        CGSize uw =[self.userLable boundingRectWithSize:CGSizeMake(DEVICE_WIDTH-PHOTO_FRAME_WIDTH*6, 0)];
        self.userLable.frame =CGRectMake(PHOTO_FRAME_WIDTH*5,PHOTO_FRAME_WIDTH+PHOTO_TIME_PADDING, uw.width, PHOTO_FRAME_WIDTH*2);
       
    }
     NSString *level = [[NSString stringWithFormat:@"%@",[[dict objectForKey:@"user"] objectForKey:@"user_level"]] replaceNullString];
    if (level.length>0) {
        _levelLabel.text =[NSString stringWithFormat:@"%@级",level];
        CGSize uw =[_levelLabel boundingRectWithSize:CGSizeMake(DEVICE_WIDTH-PHOTO_FRAME_WIDTH*6, 0)];
        _levelLabel.frame=CGRectMake(self.userLable.frame.origin.x+self.userLable.frame.size.width+PHOTO_TIME_PADDING,PHOTO_FRAME_WIDTH*2,uw.width+PHOTO_TIME_PADDING, uw.height);
        _levelLabel.layer.cornerRadius =PHOTO_FRAME_WIDTH/2;
        _levelLabel.layer.masksToBounds=YES;
        
    }
   NSString *followed = [[NSString stringWithFormat:@"%@",[[dict objectForKey:@"user"] objectForKey:@"followed"]] replaceNullString];
    _followBtn.frame=CGRectMake(DEVICE_WIDTH -PHOTO_FRAME_WIDTH*7.5,PHOTO_FRAME_WIDTH+PHOTO_TIME_PADDING, PHOTO_FRAME_WIDTH*6.5, PHOTO_FRAME_WIDTH*3);
    if([followed intValue]==0)
    {
        [_followBtn setTitleColor:UIColorFromRGB(0x3DBB2B) forState:UIControlStateNormal];
        [_followBtn setTitle:@"关注" forState:UIControlStateNormal];
    }else  if([followed intValue]==1)
    {
        [_followBtn setTitleColor:UIColorFromRGB(0xBFBFBF) forState:UIControlStateNormal];
        [_followBtn setTitle:@"已关注" forState:UIControlStateNormal];
    }else{
        [_followBtn setTitleColor:UIColorFromRGB(0xBFBFBF) forState:UIControlStateNormal];
        [_followBtn setTitle:@"互相关注" forState:UIControlStateNormal];
    }
    //
    NSString *upload_dateinfo = [[NSString stringWithFormat:@"%@",[dict objectForKey:@"upload_dateinfo"]] replaceNullString];
    if (upload_dateinfo.length>0) {
        self.timeLable.frame =CGRectMake(PHOTO_FRAME_WIDTH*5,PHOTO_FRAME_WIDTH*3, DEVICE_WIDTH-PHOTO_FRAME_WIDTH*6, PHOTO_FRAME_WIDTH*2);
        self.timeLable.text =upload_dateinfo;
    }
    
    NSString * strURL = [[NSString stringWithFormat:@"%@", [dict objectForKey:@"largePicURL"]] replaceNullString];
    if (strURL&&strURL.length>0) {
        CGFloat w = [[dict objectForKey:@"largePicWidth"] floatValue];
        CGFloat h = [[dict objectForKey:@"largePicHeight"] floatValue];
        CGFloat H =0;
        if (w>0 && h>0) {
            CGFloat fullW =DEVICE_WIDTH;
            CGFloat ratio = fullW / w;
            if (w>DEVICE_WIDTH) {
                 w = ratio *w;
                 H = ratio * h;
            }else if (w==DEVICE_WIDTH) {
                H = ratio * h;
            }else {
                 H = h;
            }
        }else{
            w=DEVICE_WIDTH;
            H=DEVICE_WIDTH;
        }
        

        
        _imgBackView.frame = CGRectMake((DEVICE_WIDTH-w)/2, fTop, w ,IMAGEHEIGHT);
        _pimageView.frame = CGRectMake(0, (IMAGEHEIGHT - H)/2 , w ,H);
        
        __block CGFloat htop = 0;
        __block UIActivityIndicatorView *activityIndicator=nil;
        __weak UIImageView *weakImageView = _pimageView;
        [weakImageView sd_setImageWithURL:[NSURL URLWithString:strURL] placeholderImage:nil options:SDWebImageLowPriority progress:^(NSInteger receivedSize, NSInteger expectedSize) {
            if (!activityIndicator)
            {
                [weakImageView addSubview:activityIndicator = [UIActivityIndicatorView.alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]];
                activityIndicator.backgroundColor=[UIColor clearColor];
                activityIndicator.center = weakImageView.center;
                [activityIndicator startAnimating];
            }
        } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
            if (error) {
                weakImageView.image=[UIImage imageNamed:@"image.png"] ;
            }else{
                weakImageView.image = image;
            }
            
            [weakImageView.layer addAnimation:[CATransition animation] forKey:kCATransition];
            [activityIndicator removeFromSuperview];
            activityIndicator = nil;
           /*
            CGFloat fullW =DEVICE_WIDTH;
            CGFloat w1 = weakImageView.image.size.width;
            CGFloat h1 = weakImageView.image.size.height;
            CGFloat ratio = fullW / w1;
            if (w1>DEVICE_WIDTH) {
                w1 = ratio *w1;
                htop = ratio *h1;
            }else if (w1==DEVICE_WIDTH) {
                htop = ratio * h;
            }else{
                htop = h1;
            }
           
            //
            _pimageView.frame = CGRectMake((DEVICE_WIDTH-w1)/2, fTop, w1 ,htop);
            //*/
            
            NSString *skuname =[[NSString stringWithFormat:@"%@", [dict objectForKey:@"title"]] replaceNullString];
            NSString *brand =[[NSString stringWithFormat:@"%@", [dict objectForKey:@"brand"]] replaceNullString];
            NSString *cat =[[NSString stringWithFormat:@"%@", [dict objectForKey:@"cat2"]] replaceNullString];
            if (skuname.length==0 && brand.length==0 &&cat.length==0) {
                [_brandView removeFromSuperview];
            }else{
                _brandView.frame =CGRectMake(0,_imgBackView.frame.origin.y+_imgBackView.frame.size.height - hightAuto(120),DEVICE_WIDTH, hightAuto(120));
            }
            CGFloat top =_brandView.frame.size.height;
            CGFloat hh0 =0;
            CGFloat x =PHOTO_FRAME_WIDTH;
            if (cat.length>0) {
                [_cateLabel setText:cat];
                CGSize optimumSize10 = [_cateLabel optimumSize];
                hh0 =optimumSize10.height;
                if ([self.key isEqualToString:@"categoryView"]) {
                    _cateLabel.textColor = [UIColor darkGrayColor];
                }
                _cateLabel.frame =CGRectMake(x,top-hh0-PHOTO_FRAME_WIDTH,optimumSize10.width, hh0);
                
                x=_cateLabel.frame.origin.x+_cateLabel.frame.size.width;
            }
            if (brand.length>0) {
                if (cat.length>0) {
                    brand =[NSString stringWithFormat:@"  /  %@",brand];
                }else{
                    brand =[NSString stringWithFormat:@"%@",brand];
                }
                [_brandLabel setText:brand];
                CGSize optimumSize11 = [_brandLabel optimumSize];
                hh0 =optimumSize11.height;
                if ([self.key isEqualToString:@"brandView"]) {
                    _brandLabel.textColor = [UIColor darkGrayColor];
                }
                _brandLabel.frame =CGRectMake(x,top-hh0-PHOTO_FRAME_WIDTH,optimumSize11.width+2, hh0);
            }
            //
            if (skuname.length>0) {
                [_skuNameLabel setText:[NSString stringWithFormat:@"%@",skuname]];
                _skuNameLine.hidden=NO;
                if (hh0>0) {
                    _skuNameLabel.frame = CGRectMake(PHOTO_FRAME_WIDTH,top-hh0-20-PHOTO_FRAME_WIDTH*2.5, _brandView.frame.size.width-PHOTO_FRAME_WIDTH*2, 20);
                    _skuNameLine.frame = CGRectMake(PHOTO_FRAME_WIDTH,_skuNameLabel.frame.origin.y+_skuNameLabel.frame.size.height+3, 16, 1);
                }else
                {
                    _skuNameLabel.frame = CGRectMake(PHOTO_FRAME_WIDTH,top-hh0-20-PHOTO_FRAME_WIDTH*2, _brandView.frame.size.width-PHOTO_FRAME_WIDTH*2, 20);
                    _skuNameLine.frame = CGRectMake(PHOTO_FRAME_WIDTH,_skuNameLabel.frame.origin.y+_skuNameLabel.frame.size.height+3,16, 1);
                }
                
                
            }else{
                _skuNameLine.hidden=YES;
            }
            //
        }];
       fTop = _imgBackView.frame.origin.y+_imgBackView.frame.size.height;
    }else
    {
        _skuNameLine.hidden=YES;
    }
    fTop = fTop+PHOTO_FRAME_WIDTH;
    //
    NSString *text =[[NSString stringWithFormat:@"%@", [dict objectForKey:@"text"]] replaceNullString];
    if (text.length>0) {
        text =[NSString stringWithFormat:@"%@",text];
        [_skuNameContent setText:text];
        CGSize optimumSize1 = [_skuNameContent optimumSize];
        _skuNameContent.frame = CGRectMake(PHOTO_FRAME_WIDTH,fTop, DEVICE_WIDTH-PHOTO_FRAME_WIDTH*2, optimumSize1.height);
        fTop = fTop+optimumSize1.height+PHOTO_FRAME_WIDTH;
    }
    
    NSString *like_cnt =[NSString stringWithFormat:@"%@",[dict objectForKey:@"like_cnt"]];
    if (like_cnt.length>0&&![like_cnt isEqualToString:@"0"]) {
        [_btnLikeV setImage:[UIImage imageNamed:@"like_icon.png"] name:like_cnt];
    }else
    {
        like_cnt =@"喜欢";
        [_btnLikeV setImage:[UIImage imageNamed:@"like_icon.png"] name:@"喜欢"];
    }
    CGSize size2=[like_cnt sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:12.0]}];
//    [_btnLikeV setFrame:CGRectMake(DEVICE_WIDTH-PHOTO_FRAME_WIDTH - (size2.width+25) ,fTop, size2.width+25, MORE_BUTTON_HEIGHT)];
    
   
    int isLike=[[dict objectForKey:@"like"] intValue];
    if (isLike) {
        [_btnLikeV setImage:[UIImage imageNamed:@"like_icon_selected.png"] name:like_cnt];
    }
    //
    NSString *reply_cnt =[NSString stringWithFormat:@"%@",[dict objectForKey:@"reply_cnt"]];
    if (reply_cnt.length>0&&![reply_cnt isEqualToString:@"0"]) {
        [_btnReplyV setImage:[UIImage imageNamed:@"pinglun_icon.png"] name:reply_cnt];
        
    }else{
        reply_cnt =@"点评";
        [_btnReplyV setImage:[UIImage imageNamed:@"pinglun_icon.png"] name:@"点评"];
        
    }
    CGSize size1=[reply_cnt sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:12.0]}];
//    [_btnReplyV setFrame:CGRectMake(_btnLikeV.frame.origin.x -(size1.width+25)- PHOTO_FRAME_WIDTH ,fTop, size1.width+25, MORE_BUTTON_HEIGHT)];
    [_btnReplyV setFrame:CGRectMake(PHOTO_FRAME_WIDTH ,fTop, size1.width+25, MORE_BUTTON_HEIGHT)];
    [_btnLikeV setFrame:CGRectMake(_btnReplyV.frame.origin.x +_btnReplyV.frame.size.width+PHOTO_FRAME_WIDTH ,fTop, size2.width+25, MORE_BUTTON_HEIGHT)];
//    [_moreBtn setFrame:CGRectMake(DEVICE_WIDTH-PHOTO_FRAME_WIDTH - MORE_BUTTON_HEIGHT ,fTop, MORE_BUTTON_HEIGHT, MORE_BUTTON_HEIGHT)];
    
  
    
    [self layoutSubviews];
}
/// 返回Cell高度
+ (CGFloat)returnCellHeight:(id)model
{
    NSDictionary *dict =(NSDictionary*)model;
    float fTop = PHOTO_FRAME_WIDTH;
    
#ifdef IMAGEHEIGHT
    fTop += IMAGEHEIGHT;
    fTop += PHOTO_FRAME_WIDTH*6;
#else
    NSString * strURL = [[NSString stringWithFormat:@"%@", [dict objectForKey:@"largePicURL"]] replaceNullString];
    if (strURL&&strURL.length>0) {
        CGFloat w =[[dict objectForKey:@"largePicWidth"] floatValue];
        CGFloat h =[[dict objectForKey:@"largePicHeight"] floatValue];
        CGFloat H =0;
        if (w>0 && h>0) {
            CGFloat fullW =DEVICE_WIDTH;
            CGFloat ratio = fullW / w;
            if (w>=DEVICE_WIDTH) {
                 H = ratio * h;
            }else{
                 H = h;
            }
            fTop +=H;
        }else{
            __block CGFloat htop = 0;
            __block UIImageView *weakImageView = [[UIImageView alloc] init];
            [weakImageView sd_setImageWithURL:[NSURL URLWithString:strURL] placeholderImage:[UIImage imageNamed:@"image.png"] options:SDWebImageLowPriority progress:^(NSInteger receivedSize, NSInteger expectedSize) {} completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                if (error) {
                    weakImageView.image=[UIImage imageNamed:@"image.png"] ;
                }else{
                    weakImageView.image = image;
                }
                CGFloat fullW =DEVICE_WIDTH;
                CGFloat w1 = weakImageView.image.size.width;
                CGFloat h1 = weakImageView.image.size.height;
                CGFloat ratio = fullW / w1;
                if (w1>=DEVICE_WIDTH) {
                    htop = ratio *h1;
                }else {
                    htop = h1;
                }
            }];
            if (htop==0) {
                htop =DEVICE_WIDTH;
            }
            fTop += htop;
            weakImageView=nil;
        }
       
       
    }
    fTop += PHOTO_FRAME_WIDTH*6;
#endif
    
    //
    NSString *text =[[NSString stringWithFormat:@"%@", [dict objectForKey:@"text"]] replaceNullString];
    if (text.length>0) {
        text =[NSString stringWithFormat:@"%@",text];
        RTLabel *textLabel =[[RTLabel alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH,0, DEVICE_WIDTH-PHOTO_FRAME_WIDTH*2,0)];
        textLabel.font = FONT(14);
        textLabel.lineSpacing = LSpacing;
        [textLabel setText:text];
        CGSize optimumSize1 = [textLabel optimumSize];
        textLabel=nil;
        CGFloat hh1 =optimumSize1.height;
        fTop =fTop + hh1+PHOTO_FRAME_WIDTH;
    }
    
    fTop = fTop +MORE_BUTTON_HEIGHT+PHOTO_FRAME_WIDTH;
    return fTop;
    
}
-(void)setCallBack:(void(^)(BEventType,UIView*,id,id,NSIndexPath *))callback
{
    self.actionBlock=callback;
}

-(void)categoryAction:(id)sender
{
    if (self.actionBlock) {
        self.actionBlock(BEventType_category,sender,self.data,self.key,self.indexPath);
    }
}
-(void)brandAction:(id)sender
{
    if (self.actionBlock) {
        self.actionBlock(BEventType_brand,sender,self.data,self.key,self.indexPath);
    }
}
-(void)goodAction:(id)sender
{
    if (self.actionBlock) {
        self.actionBlock(BEventType_good,sender,self.data,self.key,self.indexPath);
    }
}
-(void)likeAction:(id)sender
{
    if (self.actionBlock) {
        self.actionBlock(BEventType_like,sender,self.data,self.key,self.indexPath);
    }
}
-(void)commentAction:(id)sender
{
    if (self.actionBlock) {
        self.actionBlock(BEventType_comment,sender,self.data,self.key,self.indexPath);
    }
}
-(void)handleSingleTapFrom
{
    if (self.actionBlock) {
        self.actionBlock(BEventType_good,nil,self.data,self.key,self.indexPath);
    }
}
-(void)handleSingleTapFrom3
{
    if (self.actionBlock) {
        self.actionBlock(BEventType_category,nil,self.data,self.key,self.indexPath);
    }
}
-(void)handleSingleTapFrom4
{
    if (self.actionBlock) {
        self.actionBlock(BEventType_brand,nil,self.data,self.key,self.indexPath);
    }
}
-(void)handleSingleTapFrom5
{
    if (self.actionBlock) {
        self.actionBlock(BEventType_comment,nil,self.data,self.key,self.indexPath);
    }
}
-(void)handleSingleTapFromUser
{
    if (self.actionBlock) {
        self.actionBlock(BEventType_sunUser,nil,self.data,self.key,self.indexPath);
    }
}
-(void)followAction
{
    if (self.actionBlock) {
        self.actionBlock(BEventType_userfollow,nil,self.data,self.key,self.indexPath);
    }
}
-(void)moreAction
{
    if (self.actionBlock) {
        self.actionBlock(BEventType_more,nil,self.data,self.key,self.indexPath);
    }
}
@end